package ar.edu.uba.fi.jmit.aspecter;

import java.util.LinkedList;

import ar.edu.uba.fi.jmit.aspecter.core.DefinitionFactory;
import ar.edu.uba.fi.jmit.aspecter.core.exception.AspecterRuntimeException;
import ar.edu.uba.fi.jmit.aspecter.testUtils.Point;

public class DefinitionFactoryTestCase extends AspecterTestCase {

	public void testCreateClassStringListClass() {
		try {
			DefinitionFactory.create(Point.class, "getX", new LinkedList<Class<?>>(), int.class);
			DefinitionFactory.create(Point.class, "getX", new LinkedList<Class<?>>(), null);
			DefinitionFactory.create(Point.class, "getX", (LinkedList<Class<?>>)null, int.class);
		}catch(Exception e) {
			fail(e);
		}
		try {
			DefinitionFactory.create(null, "getX", (LinkedList<Class<?>>)null, int.class);
			fail("Exception should be thrown!");
		}catch(RuntimeException e) {
			//expected
		}
		
		try {
			DefinitionFactory.create(Point.class, null, (LinkedList<Class<?>>)null, int.class);
			fail("Exception should be thrown!");
		}catch(RuntimeException e) {
			//expected
		}
		
	}

	public void testCreateStringStringListString() {
		try {
			DefinitionFactory.create(Point.class.getName(), "getX", new LinkedList<Class<?>>(), int.class.getName());
			DefinitionFactory.create(Point.class.getName(), "getX", new LinkedList<Class<?>>(), null);
			DefinitionFactory.create(Point.class.getName(), "getX", (LinkedList<Class<?>>)null, int.class.getName());
		}catch(Exception e) {
			fail(e);
		}
		try {
			DefinitionFactory.create(null, "getX", new LinkedList<Class<?>>(), int.class.getName());
			fail("Exception should be thrown!");
		}catch(RuntimeException e) {
			//expected
		}catch(Exception e) {
			fail(e);
		}
		
		try {
			DefinitionFactory.create(Point.class.getName(), null, new LinkedList<Class<?>>(), int.class.getName());
			fail("Exception should be thrown!");
		}catch(RuntimeException e) {
			//expected
		}catch(Exception e) {
			fail(e);
		}
	}
	
	public void testCreateClassStringClassArrayClass() {
		try {
			DefinitionFactory.create(Point.class, "getX", new Class<?>[0], int.class);
			DefinitionFactory.create(Point.class, "getX", new Class<?>[0], null);
			DefinitionFactory.create(Point.class, "getX", (Class<?>[])null, int.class);
		}catch(Exception e) {
			fail(e);
		}
		try {
			DefinitionFactory.create(null, "getX", new Class<?>[0], int.class.getName());
			fail("Exception should be thrown!");
		}catch(RuntimeException e) {
			//expected
		}catch(Exception e) {
			fail(e);
		}
		
		try {
			DefinitionFactory.create(Point.class, null, new Class<?>[0], int.class);
			fail("Exception should be thrown!");
		}catch(RuntimeException e) {
			//expected
		}catch(Exception e) {
			fail(e);
		}
	}
	
	public void testCreateStringStringClassArrayString() {
		try {
			DefinitionFactory.create(Point.class.getName(), "getX", new Class<?>[0], int.class.getName());
			DefinitionFactory.create(Point.class.getName(), "getX", new Class<?>[0], null);
			DefinitionFactory.create(Point.class.getName(), "getX", (Class<?>[])null, int.class.getName());
		}catch(Exception e) {
			fail(e);
		}
		try {
			DefinitionFactory.create(null, "getX", new Class<?>[0], int.class.getName());
			fail("Exception should be thrown!");
		}catch(RuntimeException e) {
			//expected
		}catch(Exception e) {
			fail(e);
		}
		
		try {
			DefinitionFactory.create(Point.class.getName(), null, new Class<?>[0], int.class.getName());
			fail("Exception should be thrown!");
		}catch(RuntimeException e) {
			//expected
		}catch(Exception e) {
			fail(e);
		}
	}
	
	public void tetsCreateStringStringListString(){
		try {
			DefinitionFactory.create(Point.class.getName(), "getX", new LinkedList<Class<?>>(), int.class.getName());
			DefinitionFactory.create(Point.class.getName(), "getX", new LinkedList<Class<?>>(), null);
			DefinitionFactory.create(Point.class.getName(), "getX", (LinkedList<Class<?>>)null, int.class.getName());
		}catch(Exception e) {
			fail(e);
		}
		try {
			DefinitionFactory.create(null, "getX", new LinkedList<Class<?>>(), int.class.getName());
			fail("Exception should be thrown!");
		}catch(RuntimeException e) {
			//expected
		}catch(Exception e) {
			fail(e);
		}
		
		try {
			DefinitionFactory.create(Point.class.getName(), null, new LinkedList<Class<?>>(), int.class.getName());
			fail("Exception should be thrown!");
		}catch(RuntimeException e) {
			//expected
		}catch(Exception e) {
			fail(e);
		}
	}

	public void testCreateStringString() {
		try {
			DefinitionFactory.create(Point.class.getName(), "getX");
		}catch(Exception e) {
			fail(e);
		}
		try {
			DefinitionFactory.create(null, "getX");
			fail("Exception should be thrown!");
		}catch(RuntimeException e) {
			//expected
		}catch(Exception e) {
			fail(e);
		}
		
		try {
			DefinitionFactory.create(Point.class.getName(), null);
			fail("Exception should be thrown!");
		}catch(RuntimeException e) {
			//expected
		}catch(Exception e) {
			fail(e);
		}
	}
	
	public void testCreateConstructorClass() {
		try {
			DefinitionFactory.createConstructor(Point.class);
		}catch(Exception e) {
			fail(e);
		}
		
		try {
			DefinitionFactory.createConstructor((Class<?>)null);
			fail("Exception should be thrown");
		}catch(AspecterRuntimeException e) {
			//expected
		}catch(Exception e) {
			fail(e);
		}
	}
	
	public void testCreateConstructorString() {
		try {
			DefinitionFactory.createConstructor(Point.class.getName());
		}catch(Exception e) {
			fail(e);
		}
		
		try {
			DefinitionFactory.createConstructor((String)null);
			fail("Exception should be thrown");
		}catch(AspecterRuntimeException e) {
			//expected
		}catch(Exception e) {
			fail(e);
		}
		
		try {
			DefinitionFactory.createConstructor("NotAClass");
			fail("Exception should be thrown");
		}catch(ClassNotFoundException e) {
			//expected
		}catch(Exception e) {
			fail(e);
		}
	}
}
